package cn.com.agameofthrones.AGoTLCGCards.Fragment;

import cn.com.agameofthrones.AGoTLCGCards.R;
import cn.com.agameofthrones.AGoTLCGCards.Fragment.SingleCardActivity.CardsAdapter;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

public class DownloadImageAlertDialog extends DialogFragment {
	  public static DownloadImageAlertDialog newInstance(int title) {
		  DownloadImageAlertDialog frag = new DownloadImageAlertDialog();
	        Bundle args = new Bundle();
	        args.putInt("title", title);
	        frag.setArguments(args);
	        return frag;
	    }

	    @Override
	    public Dialog onCreateDialog(Bundle savedInstanceState) {
	        int title = getArguments().getInt("title");

	        return new AlertDialog.Builder(getActivity())
	                //.setIcon(R.drawable.alert_dialog_icon)
	                .setTitle(title)
	                .setPositiveButton(R.string.OK,
	                    new DialogInterface.OnClickListener() {
	                        public void onClick(DialogInterface dialog, int whichButton) {
	                        	int current_item=((SingleCardActivity)getActivity()).getViewPager().getCurrentItem();
	                        	CardsAdapter ap=(CardsAdapter) ((SingleCardActivity)getActivity()).getViewPager().getAdapter();
	                        	SingleCardFragment f=(SingleCardFragment) ap.getFragment(current_item);
	                        	f.doDownloadAndSwitchView();
	                        }
	                    }
	                )
	                .setNegativeButton(R.string.CANCEL,
	                    new DialogInterface.OnClickListener() {
	                        public void onClick(DialogInterface dialog, int whichButton) {
	                         //   ((FragmentAlertDialog)getActivity()).doNegativeClick();
	                        }
	                    }
	                )
	                .create();
	    }
}
